package com.whw.fy.controller;

import com.whw.fy.entity.Message;
import com.whw.fy.entity.Messagebox;
import com.whw.fy.service.MessageboxService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.checkerframework.checker.units.qual.A;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

@Api(tags = "消息盒子模块")
@RestController
@RequestMapping("/api/messagebox")
public class MessageboxController {
    @Resource
    private MessageboxService messageboxService;

    @ApiOperation(value = "添加消息记录")
    @PostMapping("/")
    public Message insert(Messagebox messagebox){
        messagebox.setMessageboxPostTime(new Date());
        return messageboxService.insertSelective(messagebox);
    }

    @ApiOperation(value = "删除消息记录")
    @DeleteMapping("/")
    public Message delete(int messageboxId){
        return messageboxService.deleteByPrimaryKey(messageboxId);
    }


    @ApiOperation(value = "修改消息记录")
    @PutMapping("/")
    public Message update(Messagebox messagebox){
        return messageboxService.updateByPrimaryKeySelective(messagebox);
    }

    @ApiOperation(value = "根据id修改状态")
    @PutMapping("/status")
    public Message updateStatusById(int status,int messageboxId){
        return messageboxService.updateMessageboxStatusByMessageboxId(status,messageboxId);
    }

    @ApiOperation(value = "查询所有消息记录")
    @GetMapping("/all")
    public Message selectAll(){
        return messageboxService.selectAll();
    }

    @ApiOperation(value = "根据接收者id查询所有消息记录")
    @GetMapping("/receiveUserId")
    public Message selectByreceiveUserId(int receiveUserId){
        return messageboxService.selectByMessageboxReceiveUserId(receiveUserId);
    }

    @ApiOperation(value = "根据消息id查询消息记录")
    @GetMapping("/id")
    public Message selectById(int messageboxId){
        return messageboxService.selectByPrimaryKey(messageboxId);
    }

}
